// BSD License (http://www.galagosearch.org/license)

package org.galagosearch.core.parse;

import org.galagosearch.tupleflow.InputClass;
import org.galagosearch.tupleflow.OutputClass;
import org.galagosearch.tupleflow.StandardStep;
import org.galagosearch.tupleflow.execution.Verified;
import java.io.IOException;
import org.galagosearch.core.types.DocumentExtent;

/**
 * Converts all tags from a document object into DocumentExtent tuples.
 * @author trevor
 */
@InputClass(className = "org.galagosearch.core.parse.VersionedDocument")
@OutputClass(className = "org.galagosearch.core.types.DocumentExtent")
@Verified
public class VersionedExtentExtractor extends StandardStep<VersionedDocument, DocumentExtent> {
    public void process(VersionedDocument vDocument) throws IOException {
        Document document=new Document();
        document.identifier=vDocument.identifier;
        document.metadata=vDocument.metadata;
        document.tags=vDocument.tags;
        document.terms=vDocument.terms;
        document.text=vDocument.text;
    	for (Tag tag : document.tags) {
            processor.process(new DocumentExtent(tag.name,
                    document.identifier,
                    tag.begin,
                    tag.end));
        }
    }
}
